<!-- 
    trim()方法会从一个字符串两端删除空白字符
    str.trim()
    trim()方法并不影响字符串本身，它返回的是一个新的字符串
    表单的字符串两边的空格。
 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text"> <button>点击</button>
    <div></div>
    <script>
        //trim取出字符串两边的空格
        var str = '    andy    ';
        var str2 = 'andy';
        console.log(str2);
        console.log(str);
        var str1 = str.trim();
        console.log(str1);

        var input = document.querySelector('input');
        var btn = document.querySelector('button');
        var div = document.querySelector('div');
        btn.onclick = function () {
            if (input.value.trim() === '') {
                alert('请输入内容');
            } else {
                console.log(input.value.trim());
                div.innerHTML = input.value;
            }
        }
    </script>
</body>

</html>